﻿@{
    ViewBag.Title = "权限角色";
    Layout = "~/Views/Shared/_ManagerLayoutPage.cshtml";
}

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body" style="padding: 1.75rem 2.8125rem;">
                <div class="row ">
                    <div class="col-md-12 clearfix" style="padding-left:0px;">
                        <p style="font-size:15px;font-weight:bold;">角色管理</p>
                        @*<div class="input-group" style="border-color:#0ea7cb;width:185px; height:30px; margin-left: 5px; margin-bottom: 9px; float: left;">
                                <button type="button" class="btn btn-primary">
                                    <i class="fa fa-align-center"></i> 新建角色
                                </button>
                                <input type="text" class="form-control" placeholder="请输入关键字" style="height:30px; width:150px;border-color: #e8e8e8;" id="para">
                                <span class="input-group-addon" style="width:35px; cursor: pointer;" id="base_search"><img src="/CJWResource/Img/search1.png" style="width:100%;"></span>
                            </div>*@
                        <div class="my-4 row">
                            <div class="ml-3">
                                <a href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/RoleManager/EditRole" class="btn btn-primary">
                                    <i class="fa fa-align-center"></i> &nbsp; 新建角色
                                </a>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <input type="text" id="para" name="input1-group2" class="form-control" placeholder="请输入角色名">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-primary" onclick="ShowModuleContent(this,1)"><i class="fa fa-search"></i></button>
                                    </span>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12" style="padding-left: 0;">
                        <div class="card" style="border-color:#f6f6f6;">
                            <div class="card-body" style="padding: 0;">
                                <div class="table-responsive">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>角色名称</th>
                                                <th>创建时间</th>
                                                <th>角色描述</th>
                                                <th>角色类型</th>
                                                @*<th style="text-align:center;">状态</th>*@
                                                <th style="text-align:center;">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="module_content"></tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12">
                        <div class="pageindex" id="page_index" style="display:none;">
                            <a id="pre_page" style="cursor:pointer;">上一页</a>
                            <span id="current_num"></span>&nbsp;/&nbsp;<span id="total_num"></span>
                            <a id="next_page" style="cursor:pointer;">下一页</a>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
    @section ChildPageScript{
        <script>


        var current_num;

        var total_num;

        $("#loading").hide();

        $(function () {

            ShowModuleContent(null,1);

        });
         $("#pre_page").click(function () {
            if (total_num != null) {
                var i = parseInt(current_num);
                if (i == 1) {

                }
                else if (i > 1) {

                    ShowModuleContent($("#pre_page"),i-1);
                }


            }
        });
        $("#next_page").click(function () {
            if (total_num != null) {
                var j = parseInt(total_num);
                var i = parseInt(current_num);
                if (j == i) {

                }
                else if (j > i) {

                    ShowModuleContent($("#next_page"),i+1);
                }
            }

        });

        function SetPageNum() {
            $("#total_num").html(total_num);
            $("#current_num").html(current_num);
            if (total_num > 1) {
                $("#page_index").show();
            }
        }
        function ShowModuleContent(obj,pagenum) {
            if (obj != null)
            {
                $(obj).attr("disabled", "disabled");
            }
            $("#module_content").empty();
            $("#page_index").hide();
            $("#loading").show();

            $.ajax({

                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "@Url.Action("GetRole", "RoleManager")",
                dataType: "json",
                data: { "pagenum": pagenum, "pagesize": 10, "para": $("#para").val()},
                type: "get",
                success: function (data) {
                    console.log(data);

                    if (data.IsError) {
                        Notic('error',data.Message);
                    }
                    else {
                        var html = "";
                        $(data.Result.content).each(function ()
                        {
                            html += "<tr>";
                            html += "<td>"+this["Name"]+"</td>";

                            html += "<td>" + this["CreateTime"].replace("T", " ") + "</td>";

                            html += "<td>" + this["Description"] + "</td>";

                            html += "<td>" + (this["IsSystem"] == 1 ? "<span class='btn-secondary'>系统角色</span>" :"<span class='btn-primary'>自定义角色</span>") + "</td>";

                            //html += "<td style='text-align:center;'>" + GetUserStatus(this["Status"]) + "</td>";

                            html += "<td style='text-align:center;'>" + (this["IsSystem"] == 1 ? "<a class='btn btn-outline-primary btn-sm' href='../RoleManager/RoleDetail?id=" + this["Id"] + "' target='_blank'>查看</a>" : "<a class='btn btn-outline-primary btn-sm' href='../RoleManager/RoleDetail?id=" + this["Id"] + "' target='_blank'>查看</a> <a class='btn btn-outline-warning btn-sm' href='../RoleManager/EditRole?id=" + this["Id"] +"'>编辑</a>") + "</td>";

                            html += "</tr>";


                        });
                        $("#module_content").html(html);

                        total_num = data.Result.total_num;

                        current_num = pagenum;
                        SetPageNum();
                    }


                },
                fail: function (data) {


                },
                complete: function (data) {


                    $("#loading").hide();

                    $(obj).removeAttr("disabled");

                }
            });
        }

        </script>
    }
